<?php
namespace Rainrock\Framework\Controller;


use Rainrock\Framework\kernel\base\CDate;
use Rainrock\Framework\kernel\base\Web;
use Rainrock\Framework\kernel\base\Jiami;
use Rainrock\Framework\kernel\Html\HtmlBase;
use Rainrock\Framework\kernel\Html\HtmlLabel;
use Rainrock\Framework\kernel\Html\HtmlImage;

/**
*	公共主详情页
*/
class XiangController extends AuthModeController{
	
	
	/**
	*	详情页
	*/
	public function indexAction()
	{
		$mid   	= $this->mid;
		$mode 	= $this->modeInfo;
		$mode->loadData($mid);
		
		$data 	= $this->m($mode->getTable())->getone($mid);
		if(!$data)return MsgView::Error('记录不存在','关闭','javascript:window.close()');
		
		$data		= $mode->mListener->onReplacers($data, 1);
		
		$title  	= $mode->getName();
		$html 		= HtmlBase::get();
		$html->setTitle($title);
		$ismobile 	= Web::isMobile();
		$border		= 'var(--border)';
		
		$mdiv 		= HtmlLabel::get()->setAlign('left')->addCss('mainbody');
		
		if(!$ismobile){
			$mdiv->addStyle('border',$border);
			$mdiv->setRadius(10);
			$mdiv->setMargin(20);
			$mdiv->addStyle('max-width','700px');
		}else{
			$mdiv->addStyle('border-top',$border);
			$mdiv->addStyle('border-bottom',$border);
		}
		
		$farr	= $mode->getFields();
		$xuhao	= 0;
		foreach($farr as $k=>$rs){
			if($rs['iszs']==0)continue;
			$fid  	= $rs['fields'];
			$type 	= $rs['fieldstype'];
			$val 	= $this->arrvalue($data, $fid);
			if($rs['isjm']==1)$val = Jiami::base64decode($val);
			
			$store	= array();
			if($type=='select' && !isset($data[''.$fid.'_textcn']) && !$this->isempt($val)){
				$store 	= $mode->getData($rs['data']);
			}
			if($store)foreach($store as $k1=>$rs1){
				if($rs1['value'] == $val){
					$data[$fid.'_textcn'] = $rs1['name'];
					if(isset($rs1['color']))$data[$fid.'_color'] = $rs1['color'];
					break;
				}
			}
			
			if($type == 'uploadimg' && !$this->isempt($val)){
				$val = HtmlImage::gets()->setSrc($val)->setWidth(100)->setHeight(100)->setOnclick('js.viewimg(this)');
			}
			if($type == 'checkbox' && !$this->isempt($val)){
				$val = ($val=='1')? '☑'.$rs['sm'].'' : '☐';
			}
			
			if($type == 'textarea' && !$this->isempt($val)){
				$val = htmlspecialchars($val);
			}
			
			$sdiv = HtmlLabel::get()->setAlign('left')->setPadding(15)->addCss('flex');
			$label= HtmlLabel::get()->setAlign('right')->addCss('hui')->setPadding(10,'right')->setWidth(85);
			$label->addCont($rs['name']);
			$sdiv->addCont($label);

			$span 	= HtmlLabel::get()->addCss('wrap')->addStyle('flex',1);
			if(isset($data[''.$fid.'_textcn']))$val = $data[''.$fid.'_textcn'];
			if(isset($data[''.$fid.'_color']))$span->setFontcolor($data[''.$fid.'_color']);
			$span->addCont($val);
			
			$sdiv->addCont($span);
			if($xuhao>0)$sdiv->addStyle('border-top',$border);
			$mdiv->addCont($sdiv);
			$xuhao++;
		}
				
		$html->addCont(HtmlLabel::get()->addCont($title)->setFontsize(20)->setMargin(20));
		$html->addCont($mdiv);
		
		$html->addScript('var mid='.$mid.',modenum=\''.$mode->getNum().'\',modegroup=\''.$mode->getGroup().'\';');
		return $html->show();
	}
	
	
}